﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Structures
{
    //public class BoundingContainer<T> where T : Bounding
    //{
    //    T bounding;


    //}



    //public interface Bounding { }

    //public class BBoxContainer : Bounding
    //{

    //}
    //public class BoundingSphereContainer : Bounding
    //{
    //}

    [Serializable]
    public enum BoundingType
    {
        Sphere,
        Box
    }
    [Serializable]
    public class Bounding
    {
        BoundingType type;
        BoundingBox bbox;
        BoundingSphere bsphere;

        

        public static Bounding CreateFromPoints(IEnumerable<Vector3> elems)
        {
            var bSphere = BoundingSphere.CreateFromPoints(elems);
            var bBox = BoundingBox.CreateFromPoints(elems);

            var volumeSphere = bSphere.GetVolume();
            var volumeBox = bBox.GetVolume();

            var b = new Bounding();
            if (volumeBox > volumeSphere)
            {
                b.type = BoundingType.Sphere;
            }
            else
            {
                b.type = BoundingType.Box;
            }
            b.bbox = bBox;
            b.bsphere = bSphere;
            return b;
        }

        public Nullable<float> Intersects(Ray ray)
        {
            if (type == BoundingType.Box)
            {
                return bbox.Intersects(ray);
            }
            else
            {
                return bsphere.Intersects(ray);
            }
        }

    }
}

